import React, { Component, createRef } from "react";

class App extends Component {
  // constructor() {
  //   super();
  //   this.ipt = createRef();
  // }

  //todo createRef用来做非受控组件的
  //todo createRef()返回的是一个地址引用
  ipt = createRef();

  handleClick() {
    // console.log(this.ipt.current);
    console.log(this.ipt.current.value);
  }

  render() {
    return (
      <>
        <h2>非受控组件</h2>
        {/* 非受控组件的初始值要用defaultValue */}
        <input type="text" ref={this.ipt} defaultValue="abc" />
        <button onClick={this.handleClick.bind(this)}>btn</button>
      </>
    );
  }
}

export default App;
